<?php

namespace app\common\validate;

use app\common\validate\Base;
class Upgrade extends Base
{

    protected $rule = [
        'up_level_id|目标等级' => 'require|integer|checkUpLevelId', 
        'smscode|短信验证码' => 'require|length:4|checkSmsCode',
    ];

    protected $message = [
        
    ];

    /**
     * 验证升级等级
     * @param  [type] $v    [description]
     * @param  [type] $rule [description]
     * @param  [type] $data [description]
     * @return [type]       [description]
     */
    protected function checkUpLevelId($v,$rule,$data){
        $allLevels = model('level')::levelData();

        $currentLevel = session('member.level_id');
        $currentScore = $allLevels[$currentLevel]['score'];
        $data = [];
        foreach($allLevels as $level):
            if($level['score']>$currentScore){
                $data[] = $level['id'];
            }
        endforeach;

        if(!in_array($v, $data)){
            $this->message['up_level_id.checkUpLevelId'] = '目标等级错误';
            return false;
        }else{
            return true;
        }
    }

}